package org.example.asynchronous;

import java.util.Random;
import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;

public class FutureTaskSty {
    public static void main(String[] args) {
        Callable<Integer> callable = () -> {
            System.out.println("pre execution");
            int randomNumber = new Random().nextInt(500);
            System.out.println("post execution");
            return randomNumber;
        };
        FutureTask<Integer> futureTask = new FutureTask(callable);
        new Thread(futureTask).start();
        System.out.println("thread has started");

        try {
            System.out.println("future task result " + futureTask.get());
        }catch (Exception e){
            e.printStackTrace();
        }
    }

}
